home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / datatypes / bmp / source / bmp.s < prev    next >
Text File  |  1995-08-11  |  7KB  |  327 lines

  1. ***************************************************************************
  2.  
  3. ; bmp.datatype v0.1 - 20/05/95 by Gunther Nikl - first version
  4.  
  5. ***************************************************************************
  6.  
  7. ; include stuff
  8.  
  9.         include    exec/types.i
  10.         include    exec/resident.i
  11.         include    exec/libraries.i
  12.         include    exec/initializers.i
  13.         include    lvo30/exec_lib.i
  14.         include    lvo30/utility_lib.i
  15.         include    lvo30/graphics_lib.i
  16.         include    lvo30/intuition_lib.i
  17.  
  18. ; import
  19.  
  20.         XREF    _GetBMP
  21.  
  22. ; specific defines
  23.  
  24. BMPVER        equ    40
  25. BMPREV        equ    4
  26.  
  27. need_mulsi3    set    1
  28.  
  29. ; macro stuff
  30.  
  31. CALL        MACRO
  32.         move.l    \2,a6
  33.         jsr    _LVO\1(a6)
  34.         ENDM
  35.  
  36. RECALL        MACRO
  37.         jsr    _LVO\1(a6)
  38.         ENDM
  39.  
  40. ADDCMD        macro
  41.         dc.w    \1-FuncTab
  42.         endm
  43.  
  44. ; class base
  45.  
  46.     STRUCTURE ClassBase,36
  47.  
  48.      ULONG    cb_SegList
  49.      ULONG    cb_SysBase
  50.      ULONG    cb_DosBase
  51.      ULONG    cb_IntBase
  52.      ULONG    cb_GfxBase
  53.      ULONG    cb_UtilityBase
  54.      ULONG    cb_DataTypesBase
  55.      ULONG    cb_SuperClassBase
  56.      ULONG    cb_BMPClass
  57.      STRUCT    cb_Lock,48
  58.  
  59.     LABEL cb_SIZEOF
  60.  
  61. LastBase    equ    cb_SuperClassBase
  62.  
  63. ***************************************************************************
  64.  
  65. start        moveq    #-1,d0
  66.         rts
  67.  
  68. ***************************************************************************
  69.  
  70. RomTag        dc.w    RTC_MATCHWORD
  71.         dc.l    RomTag
  72.         dc.l    EndTag
  73.         dc.b    RTF_AUTOINIT
  74.         dc.b    BMPVER
  75.         dc.b    NT_LIBRARY
  76.         dc.b    0
  77.         dc.l    LibName
  78.         dc.l    IdString
  79.         dc.l    InitTab
  80. EndTag
  81.  
  82. ;--------------------------------------------------------------------------
  83.  
  84. LibName        dc.b    'bmp.datatype',0
  85. IdString    dc.b    'bmp 40.4 (11.8.95) by Gunther Nikl',13,10,0
  86. DosName        dc.b    'dos.library',0
  87. IntName        dc.b    'intuition.library',0
  88. GfxName        dc.b    'graphics.library',0
  89. UtilityName    dc.b    'utility.library',0
  90. DataTypesName    dc.b    'datatypes.library',0
  91. SuperClassName    dc.b    'datatypes/'
  92. PicDTClassName    dc.b    'picture.datatype',0
  93.  
  94. ;--------------------------------------------------------------------------
  95.  
  96.         cnop    0,4
  97.  
  98. InitTab        dc.l    cb_SIZEOF
  99.         dc.l    FuncTab
  100.         dc.l    ResInfo
  101.         dc.l    InitFunc
  102.  
  103. ;--------------------------------------------------------------------------
  104.  
  105. FuncTab        dc.w    -1
  106.         ADDCMD    LibOpen
  107.         ADDCMD    LibClose
  108.         ADDCMD    LibExpunge
  109.         ADDCMD    LibExtFunc
  110.         ADDCMD    GetBMPEngine
  111.         dc.w    -1
  112.  
  113. ;--------------------------------------------------------------------------
  114.  
  115. ResInfo        INITBYTE LN_TYPE,NT_LIBRARY
  116.         INITLONG LN_NAME,LibName
  117.         INITBYTE LIB_FLAGS,(LIBF_SUMUSED!LIBF_CHANGED)
  118.         INITWORD LIB_VERSION,BMPVER
  119.         INITWORD LIB_REVISION,BMPREV
  120.         INITLONG LIB_IDSTRING,IdString
  121.         dc.w 0
  122.  
  123. ***************************************************************************
  124.  
  125.         cnop    0,4
  126.  
  127. InitFunc    move.l    a5,-(sp)
  128.         suba.l    a5,a5
  129.         cmp.w    #39,20(a6)
  130.         bcs.s    1$            ; wrong OS (not 3.x !)
  131.         move.l    d0,a5
  132.         move.l    a0,cb_SegList(a5)    ; save seglist
  133.         move.l    a6,cb_SysBase(a5)    ; cache SysBase (speed!)
  134.         lea    cb_Lock(a5),a0
  135.         RECALL    InitSemaphore
  136. 1$        move.l    a5,d0            ; return LibBase (or NULL)
  137.         move.l    (sp)+,a5
  138.         rts
  139.  
  140. ;--------------------------------------------------------------------------
  141.  
  142. OpenLibs    lea    DosName(pc),a1        ; open all libraries
  143.         moveq    #cb_DosBase,d2
  144.         bsr.s    2$
  145.         beq.s    1$            ; no dos v39+!
  146.         lea    IntName(pc),a1
  147.         moveq    #cb_IntBase,d2
  148.         bsr.s    2$
  149.         beq.s    1$            ; no intuition v39+!
  150.         lea    GfxName(pc),a1
  151.         moveq    #cb_GfxBase,d2
  152.         bsr.s    2$
  153.         beq.s    1$            ; no graphics v39+!
  154.         lea    UtilityName(pc),a1
  155.         moveq    #cb_UtilityBase,d2
  156.         bsr.s    2$
  157.         beq.s    1$            ; no utility v39+!
  158.         lea    DataTypesName(pc),a1
  159.         moveq    #cb_DataTypesBase,d2
  160.         bsr.s    2$
  161.         beq.s    1$            ; no datatypes v39+!
  162.         lea    SuperClassName(pc),a1
  163.         moveq    #cb_SuperClassBase,d2
  164. 2$        moveq    #39,d0
  165.         RECALL    OpenLibrary
  166.         move.l    d0,0(a5,d2.w)        ; store library base
  167. 1$        rts
  168.  
  169. LibOpen        movem.l    d2/a2/a5/a6,-(sp)
  170.         move.l    a6,a5
  171.         addq.w    #1,32(a5)        ; one more user
  172.         and.b    #$f7,14(a5)
  173.         move.l    a5,d2
  174.         cmp.w    #1,32(a5)        ; first opener?
  175.         bne.s    1$
  176.         lea    cb_Lock(a5),a0
  177.         CALL    ObtainSemaphore,cb_SysBase(a5)
  178.         bsr.s    OpenLibs
  179.         beq.s    3$            ; failed...
  180.         move.l    a6,-(sp)
  181.         moveq    #0,d0
  182.         moveq    #0,d1
  183.         lea    LibName(pc),a0
  184.         lea    PicDTClassName(pc),a1
  185.         suba.l    a2,a2
  186.         CALL    MakeClass,cb_IntBase(a5)
  187.         move.l    d0,cb_BMPClass(a5)
  188.         beq.s    4$            ; no class...
  189.         move.l    d0,a0
  190.         lea    BMPDispatch(pc),a1
  191.         move.l    a1,8(a0)
  192.         move.l    a5,36(a0)
  193.         RECALL    AddClass        ; make it public
  194.         move.l    a5,d2
  195. 4$        move.l    (sp)+,a6
  196.         bne.s    2$            ; leave for good
  197. 3$        bsr.s    CloseLibs
  198.         subq.w    #1,32(a5)
  199.         moveq    #0,d2
  200. 2$        lea    cb_Lock(a5),a0
  201.         RECALL    ReleaseSemaphore    ; we are through
  202. 1$        move.l    d2,d0
  203.         movem.l    (sp)+,d2/a2/a5/a6
  204.         rts
  205.  
  206. ;--------------------------------------------------------------------------
  207.  
  208. LibClose    movem.l    d2/a5/a6,-(sp)
  209.         move.l    a6,a5
  210.         moveq    #0,d0            ; do not unload
  211.         tst.w    32(a5)
  212.         beq.s    3$
  213.         subq.w    #1,32(a5)        ; one less user
  214.         bne.s    1$
  215. 3$        lea    cb_Lock(a5),a0
  216.         CALL    ObtainSemaphore,cb_SysBase(a5)
  217.         move.l    cb_BMPClass(a5),d0    ; class created?
  218.         beq.s    2$
  219.         move.l    a6,-(sp)
  220.         move.l    d0,a0
  221.         CALL    FreeClass,cb_IntBase(a5) ; free it
  222.         clr.l    cb_BMPClass(a5)
  223.         move.l    (sp)+,a6
  224. 2$        bsr.s    CloseLibs        ; close all libs
  225.         lea    cb_Lock(a5),a0
  226.         RECALL    ReleaseSemaphore    ; free semaphore here...
  227.         moveq    #0,d0
  228.         btst    #3,14(a5)
  229.         beq.s    1$            ; do not expunge!
  230.         move.l    a5,a6
  231.         bsr.s    LibExpunge        ; remove library
  232. 1$        movem.l    (sp)+,d2/a5/a6
  233.         rts
  234.  
  235. CloseLibs    moveq    #LastBase-cb_SysBase,d2
  236. 2$        move.l    cb_SysBase(a5,d2.w),d0
  237.         beq.s    1$            ; no library to close
  238.         move.l    d0,a1
  239.         RECALL    CloseLibrary
  240.         clr.l    cb_SysBase(a5,d2.w)    ; clear entry
  241. 1$        subq.w    #4,d2
  242.         bne.s    2$            ; not ready
  243.         rts
  244.  
  245. ;--------------------------------------------------------------------------
  246.  
  247. LibExpunge    movem.l    a2/a5/a6,-(sp)
  248.         move.l    a6,a5
  249.         suba.l    a2,a2
  250.         or.b    #8,14(a5)        ; set LIBF_DELEXP
  251.         tst.w    32(a5)
  252.         bne.s    1$            ; still in use...
  253.         move.l    cb_SysBase(a5),a6
  254.         move.l    cb_SegList(a5),a2    ; get seglist
  255.         move.l    a5,a1
  256.         RECALL    Remove
  257.         move.l    a5,a1
  258.         moveq    #0,d0
  259.         move.w    16(a5),d0
  260.         suba.l    d0,a1
  261.         add.w    18(a5),d0
  262.         RECALL    FreeMem
  263. 1$        move.l    a2,d0            ; return SegList (or NULL)
  264.         movem.l    (sp)+,a2/a5/a6
  265.         rts
  266.  
  267. ;--------------------------------------------------------------------------
  268.  
  269. LibExtFunc    moveq    #0,d0            ; reserved library entry
  270.         rts
  271.  
  272. ;--------------------------------------------------------------------------
  273.  
  274. GetBMPEngine    move.l    cb_BMPClass(a6),d0    ; return class pointer
  275.         rts
  276.  
  277. ***************************************************************************
  278.  
  279. ; a0 -> a5 = class
  280. ; a2       = object
  281. ; a1 -> a3 = msg
  282.  
  283. BMPDispatch    movem.l    a2-a5,-(sp)
  284.         move.l    a0,a5            ; save class
  285.         move.l    a1,a3            ; save message
  286.         bsr.s    _DoSuperMethod
  287.         move.l    d0,a2
  288.         move.l    a2,d0
  289.         beq.s    1$            ; NULL -> leave
  290.         cmpi.l    #$101,0(a3)
  291.         bne.s    1$            ; not OM_NEW !
  292.         move.l    4(a3),-(sp)        ; ops_AttrList
  293.         move.l    a2,-(sp)
  294.         move.l    a5,-(sp)
  295.         move.l    36(a5),a4
  296.         jsr    _GetBMP
  297.         lea    12(sp),sp
  298.         tst.l    d0
  299.         bne.s    1$            ; all ok !
  300.         move.l    a5,a0
  301.         pea    $102
  302.         move.l    sp,a1
  303.         bsr.s    _CoerceMethod        ; dispose object
  304.         addq.w    #4,sp
  305.         suba.l    a2,a2            ; NULL
  306. 1$        move.l    a2,d0
  307.         movem.l    (sp)+,a2-a5
  308.         rts
  309.  
  310. _DoSuperMethod    move.l    24(a0),a0        ; boopsi support
  311. _CoerceMethod    move.l    8(a0),-(sp)
  312.         rts
  313.  
  314. ;--------------------------------------------------------------------------
  315.  
  316.     IFD need_mulsi3
  317.  
  318.         XDEF    ___mulsi3
  319.  
  320. ___mulsi3:    movem.l    4(sp),d0/d1
  321.         move.l    cb_UtilityBase(a4),a0
  322.         jmp    _LVOSMult32(a0)
  323.  
  324.     ENDC
  325.  
  326.         end
  327.